var util = require('../../../utils/util.js');
var app = getApp();
var plugin = requirePlugin("myPlugin");
var dingdanPage;  //存放上一个页面的信息
var complete_ck;  //是否点击了删除或恢复订单返回
var OrderList; //存放上一个页面的列表
Page({
  /**
   * 页面的初始数据
   */
  data: {
    reason:'', //退回原因
    tszhinput:'', //商品备注
    order_remark:'', //订单备注
    content:'', //键盘初始空字符串
    inputNum: "",    //添加商品弹窗的输入框中数量
    isInput:false,  //带键盘弹窗
    isOrderremark:false,  //订单备注
    isShopremark:false,  //商品备注
    ischeck_pass:false, //审核通过
    isBackUpdate: false,  //退回修改弹窗
    is_setdel:false, //是否删除订单
    KeyboardKeys: [1, 2, 3, 4, 5, 6, 7, 8, 9, '·', 0], //键盘
    isOut:false, //出库弹窗
    weightstatus: false, //是否启用蓝牙秤
    connectionstate: "未连接", //打印机连接情况
    cont: "未连接", //电子秤连接情况
    isreject:false  //审核驳回弹窗
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    complete_ck=false;
    const pages = getCurrentPages();    //获取当前页面信息栈
    dingdanPage = pages[pages.length - 2]; //获取上一个页面信息 
    if(dingdanPage.data.status==0){  //新需求单
      OrderList = dingdanPage.data.helist;   
    }else if(dingdanPage.data.status==10){  //历史记录
      OrderList = dingdanPage.data.datas;  
    };
    this.setData({
      entPage:options.entPage,  //1代表从审批列表跳转
      d_index:options.d_index,  //列表的索引
      use_person_id:app.globalData.person_id, //当前用户的个人id
      group_id:app.globalData.group_id,  //是否为集团版
      small_type:options.small_type,  //1表示库存直采
      id: options.id,
      out_ku:options.out_ku, //无绿背景样式
      order_status:options.order_status
    });
    console.log(this.data.out_ku);
    var that = this;
    app.AppHttp('api/Client/KitchenManage', {  //判断审核权限开关
      id: app.globalData.loginInfo.id
    }, function (res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        check_open_close: res.data.ClientFind.check_open_close
      });
    });     
  },
  noneEnoughPeople:function(){
    return;
  },
  onloadDetail: function (){
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    app.AppHttp('api/Order/SmallOrderDetail', {
      id: that.data.id,
      openid: app.globalData.openid
    }, function (res) {
      console.log(JSON.stringify(res.data));       
      var goodList=res.data.orderDetail.goodList;
      if(that.data.out_ku==1){  //
        that.setData({
          outku_num_arr:Array(goodList.length).fill(0),  //初始(每一项为0)出库数量数组
          outku_price_arr:Array(goodList.length).fill(0), //初始出库单价数组  
        });
      }; 
      var info=res.data.orderDetail;      
      that.check_list(info.order_status,res.data.auth_type);
      that.setData({
        goodList: goodList,
        info: res.data.orderDetail,
        rev_order_log:res.data.orderDetail.order_log.reverse(),
        level: res.data.orderDetail.level,
        auth_type: res.data.auth_type,
        small_type:res.data.orderDetail.small_type,
        order_status: res.data.orderDetail.order_status,
        delivery_date_name: res.data.orderDetail.delivery_date_name,
        order_id: res.data.orderDetail.order_id,
        supplier_id: res.data.orderDetail.supplier_id
      }); 
      if(goodList.length>0){
        that.child = that.selectComponent('.plug-data');    
        if(that.data.out_ku==0 && info.return_type==1 && that.data.use_person_id==info.person_id
          && (info.order_status == -1 || info.order_status == -2)
        ){ //恢复左滑
          that.child.change_move(false);
          console.log('恢复');
        }else{//禁止左滑
          console.log('禁止');
          for(var i=0;i<goodList.length;i++){
            that.manychild = that.selectComponent('#plug-data'+[i]);
            that.manychild.closeButtonGroup();
          }
          that.child.change_move(true);       
        };
      }
      wx.hideLoading(); 
    })   
  },
  // 审核流程数据
  check_list:function(order_status,auth_type){
    let that = this;
    app.AppHttp('api/Order/getOrderCheck', {
      order_id:that.data.id,
      check_type:"check_order"
    }, function (res) {
      console.log(JSON.stringify(res.data));
      var check_step=-1;
      // var is_incheck=-1;
      let isme_back=-1; 
      if(res.data.check_order_list.length>0){  
        check_step=0;
        // is_incheck = res.data.check_order_list.findIndex(function(item) {
        //   return item.id == app.globalData.person_id;
        // });
        if(order_status==-1){
          isme_back = res.data.check_order_list.findIndex(function(item) {
            return item.is_checked == -1;
          });
        };
      };  
      that.setData({
        out_ku:order_status==2 && (auth_type=="manage_finance" || that.data.use_person_id==res.data.charge_info.charge_id)?1:0, //无绿背景样式
        check_list:res.data,
        check_step:check_step, //-1表示无审核人  0表示有审核人
        isme_back:isme_back   //是否发起人自己撤回==-1  自己撤回；>-1其他人撤回
        // // is_incheck:is_incheck,  //当前用户是否是审核人，>-1是，值代表他是第几个审核人；==-1，不是审核人
      });  
    }); 
  },
  // 再来一单
  again_butck:function(){
    var that = this;
    util.buttonClicked(this);  //防止重复点击
    app.AppHttp('api/Order/AgainOrder', {
      openid: app.globalData.openid,
      id: that.data.id
    }, function (res) {
      app.globalData.dingdan_show = 1;  //返回订单页面是否刷新
      app.globalData.toneed_order=1; //返回新订单
      wx.showToast({
        title: res.data.msg
      })
      wx.navigateBack({
        delta: 1
      })
    });     
  },
  // 增加商品
  addshangpin:function(){
    var order_id=this.data.order_id;
    var supplier_id=this.data.supplier_id;
    console.log(supplier_id);
    var order_status = this.data.order_status
    wx.navigateTo({
      url: '../../shangpin/shangpindetail/addsearch/addsearch?order_id=' + order_id + '&supplier_id=' + supplier_id +'&order_status=' + order_status+'&supplier_name='+''
    })
  },
  // 滑动删除该商品
  deleteOutOrder: function (event){
    var that = this;
    var order_id = this.data.info.order_id;
    var shopid = event.currentTarget.dataset.id;
    if(that.data.goodList.length==1){
      wx.showModal({
        title: '提示',
        content: "只有一个商品了,不能清空此单",
        showCancel: false,
        confirmText:"我知道了",
        success: function (res) {}
      });
    }else{
      wx.showModal({
        title: '提示',
        content: '请确认删除',
        success: function (res) {
          if (res.confirm) {
            app.myMethod.updataDingdanGood(shopid, order_id,0, that.data.tszhcontent);
            that.onloadDetail(); 
          }
        }
      });
    };       
  },
  //打开退回修改弹窗
  open_backupdate: function () {
    this.setData({
      isBackUpdate: true
    });
  },
  // 关闭退回修改弹窗
  backupdatecancel:function(){
    this.setData({
      isBackUpdate: false
    });
  },
  //填写退回原因
  setMsg: function (e) {
    this.setData({
      reason:e.detail.value
    })
  },
  //确定退回修改
  backupdateconfirm: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.request({
      url: app.globalData.url + 'api/Order/returnUpdate',
      method: "POST",
      data: {
        openid: app.globalData.openid,
        id: id,
        reasons_returning: that.data.reason
      },
      success: function (res) {
        if (res.data.status == 1) {        
          that.setData({
            order_status:-1,
            isBackUpdate: false
          });      
          // wx.navigateBack({
          //   delta:1
          // });
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'loading',
            duration: 500,
          })
        }
      }
    })
  },
  quxiaoreason:function(e){
    this.setData({
      quxiaodingdan: e.detail.value
    })
  },
  // 关闭取消订单的弹窗
  cancel: function () {
    this.setData({
      isCancel:false
    });
  },
  /**
   * 确认取消订单
   */
  confirm1:function(){
    var that = this;
    var id = that.data.id;
    wx.request({
      url: app.globalData.url + 'api/Order/ApplyCancelOrder',
      method: "POST",
      data: {
        openid:app.globalData.openid,
        id: id,
        reasons_returning: that.data.quxiaodingdan
      },
      success: function (res) {
        console.log(res.data)
        if (res.data.status == 1) {
          that.setData({
            isCancel: false
          });      
          app.globalData.dingdan_show = 1;  //返回订单页面是否刷新      
          wx.navigateBack({
            delta:1
          });
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'loading',
            duration: 1000
          })
        }
      }
    })
  },
  // 打开审核通过
  open_pass:function(){
    this.setData({
      ischeck_pass:true
    });
  },
  // 关闭审核通过
  pass_cancel:function(){
    this.setData({
      ischeck_pass:false
    });
  },
  // 审核同意
  tongyi_but:function(){
    var that=this;
    app.AppHttp('api/Order/normalOrderCheck', {
      openid: app.globalData.openid,
      order_id: that.data.id,
      check_type:'resolve',  //正常审核
      check_field:'check_order'
    }, function (res) {
      console.log(JSON.stringify(res.data));
      app.globalData.dingdan_show = 1;
      app.globalData.caigou_shua=1;
      if(res.data.data.finish == 1){
        that.okClick();
      }else{
        wx.navigateBack({
          delta:1
        });
        that.valid_news();
      };
    })
  },
  // 审核驳回
  reject_but:function(){
    this.setData({
      isreject:true,
      reject_reason:''
    });
  },
  // 关闭驳回
  cancel_reject:function(){
    this.setData({
      isreject:false
    });
  },
  // 输入驳回原因
  inputreject:function(e){
    this.setData({
      reject_reason:e.detail.value
    });
  },
  // 确定驳回
  conf_reject:function(){
    var that=this;
    console.log(that.data.reject_reason);
    app.AppHttp('api/Order/normalOrderCheck', {
      openid: app.globalData.openid,
      order_id: that.data.id,
      check_type:'reject',  //驳回
      reject_reason:that.data.reject_reason,
      check_field:'check_order'
    }, function (res) {
      console.log(JSON.stringify(res.data));
      if(that.data.entPage==1){
        app.globalData.dingdan_show = 1;
        app.globalData.caigou_shua=1;
      };   
      that.setData({
        order_status:-1,
        isreject:false
      });   
      wx.navigateBack({
        delta:1
      });
    });
  },
  //审核通过
  okClick: function () {
    var that = this;
    app.AppHttp('api/Order/changeOrderStatus', {  
      openid:app.globalData.openid,
      id: that.data.id,
      status:1
    }, function (res) {
      console.log(JSON.stringify(res.data));
      if (res.data.status == 1) {
        that.setData({
          order_status:1
        });
        wx.navigateBack({
          delta:1
        });           
      } else {
        wx.showToast({
          title: '提交失败',
          icon: 'loading',
          duration: 500,
        })
      }    
    });
  },
  // 库管接单
  keeper_order:function(){
    var that = this;
    var status;
    if(that.data.small_type==0){
      status=2;
    }else if(that.data.small_type==1){
      status=7;
    };
    app.AppHttp('api/Order/changeOrderStatus', {  
      openid:app.globalData.openid,
      id: that.data.id,
      status:status
    }, function (res) {
      console.log(JSON.stringify(res.data));
      if (res.data.status == 1) { 
        that.setData({
          order_status:status
        });
        if(status==7){
          app.globalData.dingdan_show = 1;
        };
        wx.navigateBack({
          delta:1
        });           
      } else {
        wx.showToast({
          title: '接单失败',
          icon: 'loading',
          duration: 500,
        })
      }    
    });
  },
  // 查看日志
  see_log:function(){
    util.showBuyModal(this);
    this.setData({
      is_many_allow:true
    });
  },
  // 关闭日志
  close_log:function(){
    util.hideBuyModal(this,'is_many_allow');
  },
  // 打开删除订单弹窗
  set_del: function () {
    this.setData({
      is_setdel:true
    });
  },
  // 关闭删除订单弹窗
  set_delcancel: function () {
    this.setData({
      is_setdel: false
    })
  },
  // 确定删除订单
  set_delconfirm:function(){
    var that = this;
    app.AppHttp('api/Order/delete_order', {
      openid: app.globalData.openid,
      id: that.data.id
    }, function (res) {
      console.log(JSON.stringify(res.data))
      if (res.data.status == 1) {  
        wx.showToast({
          title: '删除成功',
          icon: 'loading',
          duration: 500,
        });
        app.globalData.dingdan_show = 1;  //返回订单页面是否刷新   
        wx.navigateBack({
          delta: 1
        });   
      } else {
        wx.showToast({
          title: '删除失败',
          icon: 'loading',
          duration: 500,
        })
      }
    })
  },
  // 待编辑状态提交
  set_edit:function(){
    var that = this;
    app.AppHttp('api/Order/updateFinishOrder', {
      openid: app.globalData.openid,
      id: that.data.id,
      order_type:'x'
    }, function (res) {
      if (res.data.status == 1) {
        if(that.data.check_open_close==0){  //审核关闭时发模板消息
          that.valid_news();
        }; 
        app.globalData.dingdan_show = 1;  //返回订单页面是否刷新  
        wx.navigateBack({
          delta:1
        });     
      } else {
        wx.showToast({
          title: '提交失败',
          icon: 'loading',
          duration: 500,
        })
      }
    })
  },
  // 模板消息
  valid_news:function(){
    var that = this;
    wx.request({
      url: app.globalData.url + 'api/Message1/valid',
      method: 'GET',
      data: {
        id:that.data.id,
        message_type:"client_order_check"
      },
      success: function (res) {
        console.log(JSON.stringify(res.data));
      }
    });
  },
  // 重新提交订单
  resetOrder: function (e) {
    var id = e.currentTarget.dataset.id;
    var that = this;
    wx.request({
      url: app.globalData.url + 'api/Order/changeOrderStatus',
      method: "POST",
      data: {
        openid:app.globalData.openid,
        id: id,
        status: 0,
        field:'check_order',
        reset:1
      },
      success: function (res) {
        console.log(res.data)
        if (res.data.status == 1) {
          that.valid_news();
          that.setData({
            order_status:0
          });
          if(that.data.check_list.check_order_list.length>0){
            dingdanPage.setData({
              ["helist[" + that.data.d_index + "].current_head_portrait"]:that.data.check_list.check_order_list[0].head_portrait,
              ["helist[" + that.data.d_index + "].current_id"]:that.data.check_list.check_order_list[0].id
            }); 
            that.setData({
              order_status:0,          
              ["check_list.current_personal"]:that.data.check_list.check_order_list[0].id
            });
          }else{
            dingdanPage.setData({
              ["helist[" + that.data.d_index + "].current_id"]:null
            });
          };     
          wx.navigateBack({
            delta:1
          }); 
        } else {
          wx.showToast({
            title: '提交失败',
            icon: 'loading',
            duration: 500,
          })
        }
      }
    })
  },
  /**
   * 取消审核通过的订单
   */
  cancelOrder:function(e){
    var that = this;
    console.log(e.currentTarget.dataset.id);
    var id = e.currentTarget.dataset.id;
    that.setData({
      isCancel:true,
      id:id
    }) 
  },
  // 编辑商品下单量
  add_shop_but:function(e){
    if(this.data.order_status<0){ 
      util.showBuyModal(this);     
      var index = e.currentTarget.dataset.index;
      var info = this.data.info.goodList[index];
      var tannum=info.pr_num;  
      console.log(tannum);
      console.log(info.pr_num);
      this.setData({
        content:'',
        inputNum:'',
        isInput: true,
        inputIndex: index,
        tanimg: info.pr_cover,
        tanname: info.pr_name,
        tanalias: info.pr_alias,
        tanspecs:info.specs,
        tanunit:info.true_unit_name!='无'?info.true_unit_name:info.unit_name,
        tan_prnum:info.pr_num,
        tannum: tannum,
        tszhcontent: info.detail_remark?info.detail_remark:''
      });
    }
  },
  // 收货入库数量编辑
  add_shou_but:function(e){
    util.showBuyModal(this);
    var index = e.currentTarget.dataset.index;
    var info = this.data.info.goodList[index];
    var tannum;
    if(info.shou_num){
      tannum=info.shou_num;
    }else{
      tannum=this.data.info.is_single==1 && this.data.info.is_nuified_num==1?info.single_num:info.need_num;
    };
    this.setData({
      content:'',
      inputNum:'',
      isInput: true,
      inputIndex: index,
      tanimg:info.pr_cover,
      tanname: info.pr_name,
      tanalias: info.pr_alias,
      tanspecs:info.specs,
      tanunit:info.true_unit_name!='无'?info.true_unit_name:info.unit_name,
      tan_prnum:info.pr_num,
      tannum: tannum,
      tszhcontent: info.detail_remark?info.detail_remark:''
    });
  },
  // 出库数量编辑
  out_ku_edit:function(e){
    util.showBuyModal(this);
    var index = e.currentTarget.dataset.index;
    var info = this.data.goodList[index];
    var tannum;
    if(info.outku_num){
      tannum=info.outku_num;
    }else{
      tannum=info.pr_num*1<=info.num*1?info.pr_num:info.num;
    };
    this.setData({
      content:'',
      inputNum:'',
      isInput: true,
      inputIndex: index,
      tanimg: info.pr_cover,
      tanname: info.pr_name,
      tanunit:info.true_unit_name!='无'?info.true_unit_name:info.unit_name,
      tannum: tannum
    });
  },
  // 关闭底部商品弹窗
  add_shop_cancel:function(){
    util.hideBuyModal(this,"isInput");
  },
  // 键盘按键
  keyTap(e) {
    util.keyfunction(e,this,3);
    this.setValue();
  },
  setValue: function () {
    this.setData({
      inputNum: this.data.content
    });
  },
  // 打开商品备注
  open_remark_sh:function(){
    this.setData({
      isShopremark:true,
      tszhinput:this.data.tszhcontent
    });
  },
  // 关闭商品备注
  tszhcancel: function () {
    this.setData({
      isShopremark: false
    });
  },
  // 输入商品备注
  tszhinput: function (e) {
    this.setData({
      tszhinput: e.detail.value
    })
  },
  // 确定并关闭商品备注
  tszhconfirm: function () {
    this.setData({
      isShopremark: false,
      tszhcontent: this.data.tszhinput
    })
  },
  // 确定商品
  shop_confirm: function () {
    if (this.data.inputNum == '') {
      this.setData({
        inputNum:this.data.tannum
      });
    }
    var info = this.data.info.goodList[this.data.inputIndex];
    if (this.data.inputNum>9999.99){
      wx.showToast({
        title: '数量过大',
      })
      return;
    }
    info.pr_num = this.data.inputNum == '' ? 0 : this.data.inputNum * 1;
    if(this.data.goodList.length==1 && info.pr_num==0){
      wx.showModal({
        title: '提示',
        content: "只有一个商品了,不能清空此单",
        showCancel: false,
        confirmText:"我知道了",
        success: function (res) {}
      });
      return;
    }; 
    info.subtotal = (info.pr_num*info.unit_price*1).toFixed(2);
    info.singlePriceTotal = (info.pr_num*info.single_price*1).toFixed(2);
    info.detail_remark = this.data.tszhcontent;
    util.hideBuyModal(this,"isInput");
    var order_id = this.data.info.order_id;
    this.setData({
      ["goodList[" + this.data.inputIndex + "]"]: info
    });
    app.myMethod.updataDingdanGood(info.id, order_id, info.pr_num, this.data.tszhcontent);
    if(info.pr_num==0){
      this.onloadDetail(); 
    };
  },
  // 修改出库量
  shop_outku_conf:function(){
    if (this.data.inputNum == '') {
      this.setData({
        inputNum:this.data.tannum
      });
    }
    var info = this.data.info.goodList[this.data.inputIndex];
    if (this.data.inputNum*1>info.num){
      wx.showToast({
        title:'不得大于库存量',
      })
      return;
    };
    info.outku_num=this.data.inputNum * 1;
    var outku_num_arr=this.data.outku_num_arr;
    var outku_price_arr=this.data.outku_price_arr;
    outku_num_arr[this.data.inputIndex]=info.outku_num;   
    if(this.data.info.is_single==1 && this.data.info.is_nuified_num==1){
      outku_price_arr[this.data.inputIndex]=info.single_price*1;
    }else{
      outku_price_arr[this.data.inputIndex]=info.unit_price*1;
    };   
    util.hideBuyModal(this,"isInput");
    this.setData({
      ["goodList[" + this.data.inputIndex + "]"]: info
    });
  },
  // 一键填充(出库)
  one_key_fill_outku:function(){  
    var that = this;
    var goodList=that.data.goodList;
    var outku_num_arr=that.data.outku_num_arr;
    var outku_price_arr=that.data.outku_price_arr;
    goodList = goodList.map(function(item,index) {
      if(item.outku_num){
        outku_num_arr[index]=item.outku_num;
      }else if(!item.outku_num && goodList[index].num<goodList[index].pr_num*1){  //库存小于下单
        item.outku_num=goodList[index].num;
        outku_num_arr[index]=goodList[index].num;
      }else if(!item.outku_num && goodList[index].num>=goodList[index].pr_num*1){
        item.outku_num=goodList[index].pr_num;
        outku_num_arr[index]=goodList[index].pr_num;
      };
      
      if(that.data.info.is_single==1 && that.data.info.is_nuified_num==1){
        outku_price_arr[index]=goodList[index].single_price*1;
      }else{
        outku_price_arr[index]=goodList[index].unit_price*1;
      };
      return (item);     
    });
    that.setData({
      goodList:goodList,
      outku_price_arr:outku_price_arr
    })
  },
  // 打开订单备注
  open_remark_or:function(){
    if(this.data.order_status<0 && this.data.use_person_id==this.data.info.person_id){
      this.setData({
        isOrderremark:true,
        order_remark:this.data.info.order_remark?this.data.info.order_remark:''
      });
    }else{
      wx.showModal({
        title: '订单备注',
        content: this.data.info.order_remark,
        showCancel: false,
        confirmText: "确定",
        confirmColor: "#19a751",
        success: function (sm) {
          if (sm.confirm) {
            // 用户点击了确定 可以调用删除方法了
          } else if (sm.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    };
  },
  // 输入订单备注
  beizhuinput:function(e){
    this.setData({
      order_remark: e.detail.value
    });
  },
  // 关闭订单备注
  confirmNOkClick:function(){
    this.setData({
      isOrderremark: false
    })
  },
  // 备注确定
  confirmOkClick:function(){
    var that=this;
    var id = that.data.id;
    wx.request({
      url: app.globalData.url + 'api/Order/changeRemark',
      method: "POST",
      data: {
        id: id,
        order_remark: that.data.order_remark
      },
      success: function (res) {
        console.log(res.data);
        wx.showToast({
          title: res.data.msg,
          duration: 500
        })
        if (res.data.status == 1) {
          that.setData({
            isOrderremark: false,
            ['info.order_remark']:that.data.order_remark
          });      
        };
      }
    })
  },
  // 打开提交出库
  open_outku:function(){
    for(var i in this.data.outku_num_arr){
      if(this.data.outku_num_arr[i]==0 && this.data.goodList[i].num!=0){
        if(this.data.goodList[i].outku_num==undefined){
          wx.showLoading({
            title: '请填写出库量',
            duration:500
          });
          return;
        } 
      }
    };
    this.setData({
      isOut:true
    });
  },
  // 关闭提交出库
  outcancel:function(){
    this.setData({
      isOut:false
    });
  },
  // 确认提交出库
  outconf:function(){
    var that = this;
    util.buttonClicked(this);  //防止重复点击
    app.AppHttp('api/Order/ApiBatchOutStrock', {  
      openid:app.globalData.openid,
      id:that.data.id,
      pr_nums:that.data.outku_num_arr,
      unit_prices:that.data.outku_price_arr
    }, function (res) {
      console.log(JSON.stringify(res.data));  
      that.setData({
        isOut:false
      });     
      app.globalData.dingdan_show = 1;
      wx.navigateBack({
        delta:1
      });
    });
  },
  /**
  * 查看备注
  */
  showRemark: function (e) {
    let remark = e.currentTarget.dataset.remark;
    wx.showModal({
      title: '备注',
      content: remark,
      showCancel: false,
      confirmText: "确定",
      confirmColor: "#19a751",
      success: function (sm) {
        if (sm.confirm) {
          // 用户点击了确定 可以调用删除方法了
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.onloadDetail();  
    var that = this;
    var mconnectionstate = plugin.getconnectionstate(); //设备连接状态
    if (mconnectionstate) {
      that.setData({
        connectionstate: "已连接"
      })
    } else {
      that.setData({
        connectionstate: "未连接"
      });
    }
    wx.getConnectedBluetoothDevices({
      success(res) {
        console.log(res.devices);
        for (var i = 0; i < res.devices.length; i++) {
          if (res.devices[i].name == 'WXL-T12') {
            that.setData({
              cont: "已连接"
            })
          }
        }
      },
      fail: function () {
        that.setData({
          connectionstate: "未连接",
          cont: "未连接"
        })
      }
    });
  },
  // 启用蓝牙秤
  openweight: function () {
    if (this.data.cont == '已连接') {
      this.data.setInter = setInterval(this.change, 500);
      this.setData({
        weightstatus: true
      })
    } else {
      wx.showLoading({
        title: '蓝牙秤未连接',
        duration: 500,
        success: function() {
          wx.navigateTo({
            url: '/pages/dingdan/dingdandetail/bluetooch/bluetooch'
          })
        }
      });
    }
  },
  // 关闭蓝牙秤
  closeweight: function () {
    clearInterval(this.data.setInter);
    this.setData({
      content: "",
      weightstatus: false
    })
  },
  // 蓝牙秤上重量的动态变化
  change: function () {
    this.setData({
      content: parseFloat(app.globalData.weight.toFixed(2))
    });
    this.setValue();
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if(complete_ck==false){
      if(this.data.entPage==1){
        dingdanPage.setData({
          ["datas[" + this.data.d_index + "].order_status"]:this.data.order_status,
          ["datas[" + this.data.d_index + "].types"]:this.data.goodList.length//更新数量
        });
      }else if(!this.data.entPage && dingdanPage.data.status==0){  //新需求单    
        dingdanPage.setData({
          ["helist[" + this.data.d_index + "].current_id"]:this.data.order_status<0?null:this.data.check_list.current_personal,
          ["helist[" + this.data.d_index + "].order_status"]:this.data.order_status,
          ["helist[" + this.data.d_index + "].types"]:this.data.goodList.length//更新数量
        });
      }else if(!this.data.entPage && dingdanPage.data.status==10){  //历史记录
        dingdanPage.setData({
          ["datas[" + this.data.d_index + "].order_status"]:this.data.order_status,
          ["datas[" + this.data.d_index + "].types"]:this.data.goodList.length//更新数量
        });
      };
    };
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function(){
    this.onShow();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})